#include <stdio.h>
#include <sys/time.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <omp.h>

#define DEFAULT_N 1000000000

int main(int argc, char **argv) {
	double PI25DT = 3.141592653589793238462643;
	double local, pi_seq=0.0, pi_llc=0.0, pi_mpi=0.0, gpi_mpi, w;
	struct timeval start_time, end_time;
	double exe_time_seq;
	double exe_time_llc;
	double exe_time_mpi;
	long i, N;
	int MPI_NAME, MPI_NUMPROCESSORS;
	
	N = (argc > 1) ? atol(argv[1]) : DEFAULT_N;
	w = 1.0 / N;
	gettimeofday(&start_time, 0);
 
	#pragma omp parallel private(i, local)  //blabla bla 
   	{
		#pragma omp single 
		pi_llc = 0.0;
	 	#pragma omp for reduction (+: pi_llc) // comentario al final del pragma     
		for (i = 0; i < N; i++) {
			local = (i + 0.5)*w;
			pi_llc = pi_llc + 4.0/(1.0 + local*local);
	    }
	}
	gettimeofday(&end_time, 0);
	exe_time_llc = end_time.tv_sec - start_time.tv_sec;
	exe_time_llc = exe_time_llc + (end_time.tv_usec - start_time.tv_usec) / 1e6;
	pi_llc *= w;
	
	return 0;
}
